<%@ page language="java" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/jsp/com/include/declare.jspf" %>
<%@ include file="/WEB-INF/jsp/com/include/doctype.jspf" %>
<script language="javascript">

//로그인 submit
function login() {
    alert("layer");
    var frm = $("#loginMbrLayerForm")[0];

    // frm.action="<c:url value='/mbr/login.do'/>";

    //frm.submit();
    var loginMsg = document.getElementById("loginMsg");
    var loginFail = document.getElementById("loginFail");
    
    var mbrEml = frm.mbrEml.value ;
    var st5rHTML = "";
    var pw = frm.pw.value ;

       $.post("<c:url value='/mbr/login.do'/>",
               {
                   'mbrEml' : mbrEml,
                   'pw'     : pw
               },
               function(data){
                   alert(data);
                   var result={};
                   var items = $(data).find("item");
                   items.each(function(index,element){
                      var name = $(this).find("name").text();
                      var value = $(this).find("value").text();
                      result[name] = value;
                   });
                   
                   if(result["result"] =="OK"){
                     alert("OK");
                       loginMsg.innerHTML="이메일 아이디가 확인되었습니다.";
                       
                   }
                   else{
                       alert("NOT OK");
                       loginFail.style.display = "block";
                       
                   }
                       
               }  
           );  




}


//기존회원 로그인 submit
function extFncLogin() {
    
    var frm = $("#loginMbrLayerForm")[0];

    // frm.action="<c:url value='/mbr/login.do'/>";

    //frm.submit();
    var loginMsg = document.getElementById("loginMsg");
    var extID = frm.extMbrLoginId.value ;

    var extPW = frm.extPW.value ;

       $.post("<c:url value='/mbr/extFnLogin.do'/>",
               {
                   'extMbrId' : extID,
                   'extPw'     : extPW
               },
               function(data){
                   var result={};
                   var items = $(data).find("item");
                   items.each(function(index,element){
                      var name = $(this).find("name").text();
                      var value = $(this).find("value").text();
                      result[name] = value;
                   });
                   if(result["result"] =="OK"){
                     alert("OK");
                       var frm = $("#loginMbrLayerForm")[0];
                       frm.action="<c:url value='/mbr/extClasAgr.do'/>";
                      frm.submit();
                       return true;
                   }
                   else{
                       alert("NOT");
                       loginMsg.innerHTML="<font color=\"red\">아이디나 비밀번호를 다시 확인하여 주세요.</font>";

                       return true;                      
                   }
                       
               }  
           );  

 return false;


}

//회원가입(약관동의쪽으로 이동)
function clasAgr(){

    var frm = $("#loginMbrLayerForm")[0];
    frm.action="<c:url value='/mbr/clasAgr.do'/>";
    frm.submit();
}


function extLoginForm(){

    var newLogF = document.getElementById("emlLoginDiv");
    var extLogF = document.getElementById("extLoginPopup");
    newLogF.style.display = "none";
    extLogF.style.display = "block";
    /*
    if( newLogF.style.display == "none") {
        newLogF.style.display = "block";
    }else{
        newLogF.style.display = "none";
    }

    if( extLogF.style.display == "none") {
        extLogF.style.display = "block";
    }else{
        extLogF.style.display = "none";
    }
    */
}

function reForm(){
    var newLogF = document.getElementById("emlLoginDiv");
    var extLogF = document.getElementById("extLoginPopup");
    newLogF.style.display = "block";
    extLogF.style.display = "none";
    /*
    if( newLogF.style.display == "none") {
        newLogF.style.display = "block";
    }else{
        newLogF.style.display = "none";
    }

    if( extLogF.style.display == "none") {
        extLogF.style.display = "block";
    }else{
        extLogF.style.display = "none";
    } 
    */
}

</script>
<body>
<form id="loginMbrLayerForm" name="loginMbrLayerForm" method="post" onsubmit="return false;">

<!-- 로그인 -->
        <div class="layerpopup-contents" id="emlLoginDiv">
            <div class="login-form-wrap">
                <div class="login-form">
                    <div>
                        <strong><img src="/images/layerpopup/txt_login01.gif" alt="이메일 아이디" /></strong>
                        <input type="text" class="txt"  name="mbrEml" id="mbrEml" style="width:164px;" title="이메일 아이디 입력" />
                    </div>
                    <div class="pw">
                        <strong><img src="/images/layerpopup/txt_login02.gif" alt="비밀번호" /></strong>
                        <input type="password" class="txt" name="pw" id="pw" style="width:164px;" title="비밀번호 입력" />
                    </div>
                    <input type="image" src="/images/layerpopup/btn_confirm.gif" alt="확인" class="input-btn" onClick="login()"/>
                </div>
                
                <div class="etc-function">
                    <input type="checkbox" class="check" id="" />
                    <label for="">아이디 저장1</label>
                    <span class="bar">|</span>
                    <a href="#">아이디 찾기</a>, <a href="#">비밀번호 찾기</a>
                </div>
                <div class="member-conrol">
                    <a href="javascript:clasAgr();"><img src="/images/layerpopup/btn_join.gif" alt="회원가입" /></a>
                    <a href="javascript:extLoginForm();"><img src="/images/layerpopup/btn_member_replace.gif" alt="기존회원 전환" /></a>
                </div>
            </div>
        </div>
        <div id="extLoginPopup" name="extLoginPopup" style="display:none">
            <div class="layerpopup-contents">
                <div class="login-form-wrap">
                    <div class="login-form">
                        <div>
                            <strong><img src="/images/layerpopup/txt_login03.gif" alt="아이디" /></strong>
                            <input type="text" class="txt" style="width:164px;" title="아이디 입력" id="extMbrLoginId" name="extMbrLoginId" />
                        </div>
                        <div class="pw">
                            <strong><img src="/images/layerpopup/txt_login02.gif" alt="비밀번호" /></strong>
                            <input type="password" class="txt" style="width:164px;" title="비밀번호 입력" id="extPW" name="extPW"/>
                        </div>
                        <input type="image" src="/images/layerpopup/btn_confirm.gif" alt="확인" class="input-btn" onclick="extFncLogin()"/>
                    </div>        
                    <p class="repace-comment">* 기존 현대자동차 회원님께서 신 회원제(이메일아이디)로 변환하는 절차 입니다.</p>
        
                </div>
            </div>    
        </div>   
       

<!-- //로그인 -->
<div id= "loginMsg" name="loginMsg" style="display:none" ></div>
<div id="loginFail" name="loginFail" style="display:none" >
</div>
</form>

</body>
</html>